package org.ponly.cta4j.drawing.text.glyphsvisitor;

import org.ponly.cta4j.drawing.text.Glyphs;

import java.awt.geom.Rectangle2D;
import java.security.SecureRandom;
import java.util.Random;

/**
 * @author mag
 * @Date 7 mars 2008
 */
public class TranslateGlyphsVerticalRandomVisitor implements GlyphsVisitor {
    private Random myRandom = new SecureRandom();
    private double verticalRange = 1;

    public TranslateGlyphsVerticalRandomVisitor(double verticalRange) {
        this.verticalRange = verticalRange;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void visit(final Glyphs glyphs, final Rectangle2D backgroundBounds) {
        for (int i = 0; i < glyphs.size(); i++) {
            double tx = 0;
            double ty = verticalRange * myRandom.nextGaussian();
            glyphs.translate(i, tx, ty);
        }
    }
}
